iT邦幫忙

0

dJango template 和 view 溝通的新做法

  • 分享至 

  • xImage
  •  

主要是view中的函數可以直接返回,作為http的response:
view中:

return JsonResponse({'pathname': pathName, 'polygon': json.dumps(originGpxManager.GetPolygon(pathName))}) 

template中:

//send to servers
function reqListener() {
console.log(typeof(this.responseText),typeof(this.response));
console.log(this)

var response = JSON.parse(this.responseText);
console.log(response);

var pathName = decodeURI(response['pathname']);
var polygon = response['polygon'];
console.log('pathName', pathName);

//add polygon to gpxmanager
pathManger.AddOriginPolygon(pathName, polygon);
}

var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", 'decodePathLine_toPolygon' + '/'+pathname+'/' + str_paths);
oReq.send();

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言